package com.sloera.springcloud.controller;

import com.sloera.java.common.tool.entity.R;
import com.sloera.springcloud.payment.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * 消费模块，通过restTemple调用结果
 *
 * @author SloeraN
 * @version 1.0
 * @class com.sloera.springcloud.controller.OrderController
 * @date 2020/8/12
 */
@RestController
@Slf4j
public class OrderController {
    private static final String PAYMENT_URL = "http://localhost:8001";
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/consumer/payment/create")
    public R create(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, R.class);
    }

    @GetMapping("/consumer/payment/get/{id}")
    public R getPayment(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, R.class);
    }
}
